/**
 * @description: 防抖函数
 * @param {Function} fn
 * @param {number} delay
 * @return {*}
 */
export function debounce(fn: Function, delay: number = 200): any {
  let timer: number | undefined;
  return {
    clear: function () {
      timer && clearTimeout(timer);
      timer = undefined;
    },
    exec: function (...args: any) {
      timer && clearTimeout(timer);
      timer = window.setTimeout(function () {
        fn.apply(fn, args);
      }, delay);
    },
  };
}
